package com.heima.media.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.WmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理系统")
public class WnChannelController {
    @Autowired
    WmChannelService wmChannelService;
    @ApiOperation(value = "频道分页列表" ,notes = "author:ztz")
    @ApiImplicitParam(name = "channelDto",dataType = "ChannelDto",required = true,value = "查询对象")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDto channelDto){
       return wmChannelService.pageInfo(channelDto);
    }
    /**
     * 新增频道
     */
    @ApiOperation(value = "频道新增" ,notes = "author:ztz")
    @ApiImplicitParam(name = "WmChannel",dataType = "ChannelDto",required = true,value = "查询对象")
    @PostMapping
    public ResponseResult<Integer> Insert(@RequestBody WmChannel channelDto){
        return wmChannelService.Insert(channelDto);
    }

    /**
     * 修改频道
     * @param wmChannel
     * @return
     */
    @ApiOperation(value = "频道修改" , notes = "author:ztz")
    @ApiImplicitParam(name = "WmChannel" , dataType = "wmChannel",required = true,value = "查询对象")
    @PutMapping
    public ResponseResult Update(@RequestBody WmChannel wmChannel){
         wmChannelService.updateById(wmChannel);
         return ResponseResult.okResult();
    }
    /**
     * 删除频道
     */
    @DeleteMapping("/{id}")
    public ResponseResult Delete(@PathVariable Integer id){
        wmChannelService.removeById(id);
        return ResponseResult.okResult();
    }
    /**
     * 前端：频道列表查询
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
       return wmChannelService.Channels();
    }


}
